home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
337_01
/
l_trim.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-12
|
2KB
|
98 lines
/* Copyright (c) James L. Pinson 1990,1991 */
/********************** L_TRIM.C ***************************/
#include "mydef.h"
/*****************************************************************
Usage: void make_string(char *string,char letter,int count);
char *string = pointer to string to build.
char letter = letter to replicate.
int count = length of string.
Builds a string consisting only of the character specified
by "ch". The string is the length specified by "count".
Example: make_string (string,'x',10);
results: string = "xxxxxxxxxx"
*****************************************************************/
void make_string(char *string,char letter,int count)
{
int j;
for (j=0;j<count;j++) string[j]=letter;
string[j]='\0';
}
/*****************************************************************
Usage: void trim_left(char *string)
char *string = string to strip of left spaces.
Removes all the leftmost spaces from the string specified by
"string".
*****************************************************************/
void trim_left(char *string)
{
int i=0;
int j=0;
if (!strlen(string)) return;
while(string[i]== ' ' && string[i] != '\0') i++;
while (string[i] != '\0')
string[j++]= string[i++];
string[j]='\0';
}
/*****************************************************************
Usage: void trim_right(char *string);
char *string = string to strip of right spaces.
Removes all the rightmost spaces from the string specified by
"string".
*****************************************************************/
void trim_right(char *string)
{
int pos;
pos = strlen(string)-1;
while(string[pos]==' '){
string[pos--]= '\0';
if (pos < 0) break;
}
}
/*****************************************************************
Usage: void trim(char *string)
char *string = string to strip of left and right spaces.
Removes all the leftmost and rightmost spaces from the string
specified by "string".
*****************************************************************/
void trim(char *string)
{
trim_left(string);
trim_right(string);
}